﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using S.Services.SheepMale.Api.Application.Command.PurchaseCommand;
using S.Services.SheepMale.Api.Extensions;
using System.Security.Claims;

namespace S.Services.SheepMale.Api.Controllers
{
    /// <summary>
    /// 个体采购管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = nameof(ApiVersionInfo.个体采购))]
    public class EntityPurchaseController : ControllerBase
    {
        private readonly IMediator mediator;

        public EntityPurchaseController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 采购添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> HandleAddPurchase(PurchaseAddCommand request, CancellationToken cancellationToken)
        {
            request.CreateBy = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            return Ok(await mediator.Send(request));
        }
        /// <summary>
        /// 个体采购删除
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<IActionResult> HandleDelPurchase([FromQuery]PurchaseDelCommand request, CancellationToken cancellationToken)
        {
            return Ok(await mediator.Send(request));
        }
        /// <summary>
        /// 个体采购批删
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<IActionResult> HandleDelAllPurchase([FromQuery]PurchaseDelAllCommand request, CancellationToken cancellationToken)
        {
            return Ok(await mediator.Send(request));
        }
        /// <summary>
        /// 个体采购修改
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<IActionResult> HandleEditPurchase( PurchaseEditCommand request, CancellationToken cancellationToken)
        {
            request.UpdateBy = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            return Ok(await mediator.Send(request));
        }
        /// <summary>
        /// 个体采购批量审核
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<IActionResult> HandleEmaminePurchase([FromQuery]PurchaseExamineCommand request, CancellationToken cancellationToken)
        {
            
            return Ok(await mediator.Send(request));
        }
        /// <summary>
        /// 个体采购批量重新审核
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<IActionResult> HandleNewEmaminePurchase([FromQuery]PurchaseNewExamineCommand request, CancellationToken cancellationToken)
        {
            return Ok(await mediator.Send(request));
        }
    }
}
